﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using ST.Buz.Base.Enums;
using ST.Buz.Service;
using ST.Common.Util.Model;
using ST.Common.Util.Mvc;
using ST.Common.Util.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ST.Buz.Web
{
	/// <summary>
	/// 具体业务的一些扩展方法
	/// </summary>
	public class MyBaseController : BaseController
	{
		public MyBaseController(ILogger<MyBaseController> _logger) : base(_logger)
		{
		}

		protected MyBaseController(ILogger _logger) : base(_logger)
		{
		}

		/// <summary>
		/// 微信Referer头部正则
		/// </summary>
		private static Regex WX_REFERER_REG = new Regex("https://servicewechat.com/([a-zA-Z0-9]+)/([a-zA-Z0-9\\.]+)/page-frame.html");

		public override void OnActionExecuting(ActionExecutingContext context)
		{
			if (context.HttpContext.Request.Method == "GET")
			{
				var serviceSysSiteConfig = context.HttpContext.RequestServices.GetService(typeof(IServiceSysSiteConfig)) as IServiceSysSiteConfig;
				var siteConfig = serviceSysSiteConfig.GetSiteConfig();
				if (siteConfig != null)
				{
					ViewBag.SysName = siteConfig.Name;
					ViewBag.AppVersion = siteConfig.AppVersion;
					ViewBag.DbVersion = siteConfig.DBVersion;
				}
			}
		}
	}
}
